"use strict";
cc._RF.push(module, '6c4ddBj6qlAgK5nYh6VFBEL', 'BadFly');
// Script/BadFly.js

"use strict";

// Learn cc.Class:
//  - [Chinese] https://docs.cocos.com/creator/manual/zh/scripting/class.html
//  - [English] http://docs.cocos2d-x.org/creator/manual/en/scripting/class.html
// Learn Attribute:
//  - [Chinese] https://docs.cocos.com/creator/manual/zh/scripting/reference/attributes.html
//  - [English] http://docs.cocos2d-x.org/creator/manual/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
//  - [Chinese] https://docs.cocos.com/creator/manual/zh/scripting/life-cycle-callbacks.html
//  - [English] https://www.cocos2d-x.org/docs/creator/manual/en/scripting/life-cycle-callbacks.html

cc.Class({
    extends: cc.Component,

    properties: {
        flySpeed: 0, //速度
        level: 1, //等级
        flyTime: 0, //飞行时间
        flyLength: 0, //飞行距离
        type: 0, //飞机类型
        bloodNum: 0, //血量
        progressBarView: {
            type: cc.ProgressBar,
            default: null
        },
        speed: 1
    },

    //敌机向下飞行方法
    badFlyDownAction: function badFlyDownAction() {
        //		this.node.rotation = 90;
        var flyDown = cc.moveBy(this.flyTime, cc.v2(0, -this.flyLength));
        return flyDown;
    },

    doClean: function doClean() {
        if (this.node.y < -450 || this.node.x > 300 || this.node.x < -300) {
            //this.node.removeFromParent();
            this.node.destroy();
            //console.log("飞机越出边界自动销毁!!");
        }
    },

    /**
     * 更新飞机血条
     * @param {Object} progressBar
     * @param {Object} dt
     */
    _updateProgressBar: function _updateProgressBar(powerNum) {
        var progress = this.progressBarView.progress;
        if (progress > 0) {
            progress -= 1 / (2 * this.level) * powerNum;
        }
        if (progress <= 0) {
            this.progressBarView.progress = 0;
            return true;
        } else {
            this.progressBarView.progress = progress;
            return false;
        }
    },

    onLoad: function onLoad() {
        this.progressBarView.progress = 1.0;
        this.node.runAction(this.badFlyDownAction());
    },
    start: function start() {},
    update: function update(dt) {
        this.doClean();
    }
});

cc._RF.pop();